
// pages/b/b.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        swiper:['/pages/img/Is1qaU5sQA_small.jpg','/pages/img/R-C.png','/pages/img/90.png'],
        active:1,
        gridList:[{
            name:'酒吧',
            id:1,
            icon:"/pages/img/20_画板 1.png"
        },
    {
        name:'咖啡厅',
            id:2,
            icon:"/pages/img/咖啡.png"
    },
{
    name:'KTV',
            id:3,
            icon:"/pages/img/KTV.png"
},
{
    name:'棋牌室',
            id:4,
            icon:"/pages/img/打牌.png"
},
{
    name:'电玩游戏厅',
            id:5,
            icon:"/pages/img/游戏手柄.png"
},
{
    name:'密室逃脱',
            id:6,
            icon:"/pages/img/钥匙 (1).png"
},
{
    name:'公园',
            id:7,
            icon:"/pages/img/公园.png"
},
{
    name:'篮球场',
            id:8,
            icon:"/pages/img/篮球 (1).png"
},
{
    name:'台球室',
            id:9,
            icon:"/pages/img/台球.png"
},
{
    name:'网吧',
            id:10,
            icon:"/pages/img/电脑.png"
},
{
    name:'影院',
            id:11,
            icon:"/pages/img/2-电影院.png"
},
{
    name:'健身房',
            id:12,
            icon:"/pages/img/健身房.png"
},
{
    name:'奶茶店',
            id:13,
            icon:"/pages/img/珍珠奶茶.png"
},
{
    name:'羽毛球馆',
            id:14,
            icon:"/pages/img/羽毛球.png"
},
{
    name:'更多',
            id:0,
            icon:"/pages/img/更多_填充.png"
}],
        tabList:[{
            title:'酒吧',
            id:1
        },{
            title:'咖啡厅',
            id:2
        },{
            title:'KTV',
            id:3
        },{
            title:'篮球场',
            id:8
        }],
        locationList:[],
        pageSize: 1,
        pageIndex: 1,
        windowHeight: 0,
        triggered: false
    },
    setActive(e){
        this.setData({
            active:e.currentTarget.dataset.id,
            pageIndex: 1,
            locationList: []
        })
        this.getLocationList()
    },
    /* 获取场所列表 */
    async getLocationList(){
        const { active, pageIndex, pageSize, locationList} = this.data
        const { result: { data } } = await wx.cloud.callFunction({
            name:'getLocationList',
            data:{
                type: active,
                pageSize,
                pageIndex
            }
        })
        this.setData({
            locationList: Array.from(new Set([...locationList, ...data].map(item => JSON.stringify(item)))).map(item => JSON.parse(item)),
            triggered: false
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.getLocationList()
        const {windowHeight}= wx.getWindowInfo()
        this.setData({
            windowHeight : windowHeight - 50
        })
    },
    /*上拉加载*/
    scrolltolower(){
        this.setData({
            pageIndex: this.data.pageIndex += 1
        })
        this.getLocationList()

    },
    /*下拉刷新*/
    refresherrefresh(){
        this.setData({
            pageIndex: 1,
            locationList: []
        })
        this.getLocationList()
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        this.getLocationList()
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})